/**
 * Created by George on 2018/1/28.
 * mainCtrl
 */
"use strict";
define(['angular'], function (angular) {
    // 将本控制器函数作为结果返回给router.js
    var mainCtrl = function ($scope) {
        $scope.menuList = [
            {name: "user", href: "#/user", class: "item-select"},
            {name: "activity", href: "#/activity", class: ""},
            {name: "dues", href: "#/dues", class: ""},
            {name: "note", href: "#/note", class: ""}
        ];
        $scope.value = "this is main ctrl.";
        $scope.welcome_info = "this is main ctrl.";


        function init() {
            var url = window.location.href;
            var routeValue = url.substr(url.indexOf('#'));
            initRoute(routeValue);
        }

        function initRoute(routeValue) {
            var itemSelect = false;
            for (var index = 0; index < $scope.menuList.length; index++) {
                if (routeValue.indexOf($scope.menuList[index].href) > -1) {
                    itemSelect = true;
                    $scope.menuList[index].class = 'item-select';
                } else {
                    $scope.menuList[index].class = '';
                }
            }
            if (!itemSelect && $scope.menuList.length > 0) {
                $scope.menuList[0].class = 'item-select';
            }
        }

        $scope.itemClick = function (data) {
            initRoute(data.href)
        };


        //app start
        init();
    };

    return mainCtrl;
});